/**
 * 用户信息
 * */
export default {
  namespaced: true,
  state: {
    // 用户信息
    info: {},
    userRole: null,
    userRoleTow: null,
    roleAuth: [],
    roleName: [],
    restree: [],

    subjectAuth: [], // 主体管理
    mapAuth: [], // 产业地图
    modelAuth: [], // 3D模型
    saleAuth: [], // 产品销售
  },
  actions: {
    /**
     * @description 设置用户数据
     * @param {Object} state vuex state
     * @param {Object} dispatch vuex dispatch
     * @param {*} info info
     */
    set({ state, dispatch }, info) {
      return new Promise(async (resolve) => {
        // store 赋值
        state.info = info;
        // 持久化
        await dispatch(
          'admin/db/set',
          {
            dbName: 'sys',
            path: 'user.info',
            value: info,
            user: true,
          },
          { root: true }
        );
        // end
        resolve(null);
      });
    },
    /**
     * @description 从数据库取用户数据
     * @param {Object} state vuex state
     * @param {Object} dispatch vuex dispatch
     */
    load({ state, dispatch }) {
      return new Promise(async (resolve) => {
        // store 赋值
        state.info = await dispatch(
          'admin/db/get',
          {
            dbName: 'sys',
            path: 'user.info',
            defaultValue: {},
            user: true,
          },
          { root: true }
        );
        // end
        resolve(null);
      });
    },
  },
  mutations: {
    setUserRole(state, data) {
      state.userRole = data;
    },
    setUserTow(state, data) {
      state.userRoleTow = data.sysUser;
    },
    setRoleAuth(state, data) {
      state.roleAuth = data;
    },
    setRoleName(state, data) {
      state.roleName = data;
    },
    getResTreeData(state, data) {
      state.restree = data;
    },
    setSubjectAuth(state, data) {
      state.subjectAuth = data;
    },
    setMapAuth(state, data) {
      state.mapAuth = data;
    },
    setModelAuth(state, data) {
      state.modelAuth = data;
    },
    setSaleAuth(state, data) {
      state.saleAuth = data;
    },
  },
};
